<template>
	<div>
		<navigation-bar>
			<div class="searchContent">
				<el-input
					v-model="name"
					placeholder="请输入名称"
					size="mini"
					style="width: 150px; margin-right: 10px"
				></el-input>
				<el-select
					v-model="isDone"
					size="mini"
					placeholder="请选择是否完成实验"
					style="width: 180px; margin-right: 10px"
				>
					<el-option
						v-for="item in isDoneList"
						:key="item.value"
						:label="item.label"
						:value="item.value"
					>
					</el-option>
				</el-select>
				<custom-button
					type="search"
					style="margin-right: 10px"
					@searchClick="searchClick"
				></custom-button>
				<custom-button
					type="reset"
					style="margin-right: 10px"
					@resetClick="resetClick"
				></custom-button>
				<custom-button
					type="add"
					title="总结"
					style="margin-right: 10px"
					@addClick="addClick"
				></custom-button>
			</div>
		</navigation-bar>
		<table-index
			:dataSource="dataSource"
			:tableColumns="tableColumns"
			btnListWidth="70px"
			:btnList="btnList"
			:pageSize="pageSize"
			:pageCount="pageCount"
			:pageNo="pageNo"
			selection
			@pageChange="pageChange"
			@viewRow="viewRow"
			@handleSelectionChange="handleSelectionChange"
		></table-index>

		<div v-if="dialogShow">
			<custom-dialog
				:title="dialogTitle"
				size="large"
				@dialogClose="dialogClose"
			>
				<form-index
					:formConfig="formConfig"
					@submit="submit"
					:type="type"
					ref="form"
				>
					<!--  <div>这里还可以插入其它内容进行拓展</div> -->
				</form-index>
			</custom-dialog>
		</div>
	</div>
</template>

<script>
	import { researchSummaryForm } from "@/assets/form/managementCenter/subjectManagement/researchSummaryForm"
	import customDialog from "@/components/customComponents/customDialog"
	import tableIndex from "@/components/customComponents/customeTable/tableIndex"
	import customButton from "@/components/customComponents/customForm/customButton"
	import formIndex from "@/components/customComponents/customForm/formIndex"
	import navigationBar from "@/components/customComponents/managementCenter/navigationBar"
	import { AjaxCommon } from "@/libs/apiCommon"
	import { PopupCommon } from "@/libs/popupCommon"
	import { SessionCommon } from "@/libs/sessionCommon"
	import { Utility } from "@/libs/utility"
	export default {
		components: {
			navigationBar,
			customButton,
			tableIndex,
			customDialog,
			formIndex,
		},
		data() {
			return {
				name: "",
				isDone: "",
				isDoneList: Utility.getDictList("is_done"),
				// table 相关参数  begin
				dataSource: [],
				tableColumns: [
					{
						prop: "filterNo",
						label: "筛选号",
					},
					{
						prop: "randomNo",
						label: "随机号",
					},
					{
						prop: "groupSeq",
						label: "入组顺序号",
						width: 120,
					},
					{
						prop: "drugSeq",
						label: "给药顺序号",
					},
					{
						prop: "examineeName",
						label: "受试者姓名",
						width: 120,
					},
					{
						prop: "sex",
						label: "性别",
						dictName: "sex",
					},
					{
						prop: "isDone",
						label: "是否完成试验",
						width: 120,
						dictName: "is_done",
					},
					{
						prop: "summaryByName",
						label: "总结人",
						width: 120,
					},
					{
						prop: "doneOrOutTime",
						label: "完成/退出时间",
						width: 180,
					},
					{
						prop: "doneOrOutReason",
						label: "完成/退出原因",
						width: 180,
					},
					{
						prop: "summaryTime",
						label: "总结时间",
						width: 180,
					},
				],
				btnList: ["view"],
				pageSize: 20,
				pageCount: 100,
				pageNo: 1,
				// table 相关参数  end

				// 弹窗是否显示
				dialogShow: false,
				// 弹窗标题 (新增修改不同)
				dialogTitle: "",

				// form的配置信息
				formConfig: researchSummaryForm,
				type: "add",
				leftSelectIds: [],
			}
		},
		methods: {
			handleSelectionChange(e) {
				this.leftSelectIds = e
			},
			submit(d) {
				let self = this
				console.log(d)
				d.examineeCode = this.leftSelectIds[0].examineeCode
				d.examineeEn = this.leftSelectIds[0].examineeEn
				d.examineeName = this.leftSelectIds[0].examineeName
				d.sex = this.leftSelectIds[0].sex
				d.filterNo = this.leftSelectIds[0].filterNo
				AjaxCommon("/ccdc/pm/em/root/emResearchSummary/summary", "post", d)
					.then((res) => {
						if (res.data.code == 200) {
							PopupCommon.notify("success", "操作成功")
							self.initPage()
							self.dialogClose()
						} else {
							PopupCommon.notify("error", res.data.message)
						}
					})
					.catch((err) => {
						PopupCommon.notify("error", err.message)
					})
			},
			dialogClose() {
				this.dialogShow = false
			},
			searchClick() {
				this.pageNo = 1
				this.initPage()
			},
			resetClick() {
				this.name = ""
			},
			addClick() {
				if (this.leftSelectIds.length != 1) {
					PopupCommon.notify("info", "请勾选一个受试者")
					return
				}
				let formConfigItem = this.formConfig
				formConfigItem.map((t) => {
					Object.keys(t).map((res) => {
						if (res == "fieldName") {
							if (t[res] == "examineeCode") {
								t.filedValue = this.leftSelectIds[0].examineeCode
							} else if (t[res] == "examineeName") {
								t.filedValue = this.leftSelectIds[0].examineeName
							} else if (t[res] == "id") {
								t.filedValue = this.leftSelectIds[0].id
							} else if (t[res] == "examineeEn") {
								t.filedValue = this.leftSelectIds[0].examineeEn
							} else if (t[res] == "filterNo") {
								t.filedValue = this.leftSelectIds[0].filterNo
							} else if (t[res] == "isBlack") {
								t.filedValue = "0"
							} else {
								t.filedValue = ""
							}
						}
					})
				})
				this.formConfig = formConfigItem
				this.type = "add"
				this.dialogShow = true
				this.dialogTitle =
					"新增" + JSON.parse(SessionCommon.getCurrentMenuInfo()).title
			},
			// 分页点击事件
			pageChange(p) {
				this.pageNo = p
				this.initPage()
			},
			viewRow(d) {
				this.type = "look"
				let formConfigItem = this.formConfig
				formConfigItem.map((t) => {
					Object.keys(t).map((res) => {
						if (res == "fieldName") {
							t.filedValue = d.data[t[res]]
						}
					})
				})
				this.formConfig = formConfigItem
				this.dialogShow = true
				this.dialogTitle =
					"查看" + JSON.parse(SessionCommon.getCurrentMenuInfo()).title
			},
			// 初始化事件
			initPage() {
				let self = this
				AjaxCommon("/ccdc/pm/em/root/emResearchSummary/listByPage", "post", {
					examineeName: this.name,
					isDone: this.isDone,
					pageNo: this.pageNo,
					pageSize: this.pageSize,
				}).then((res) => {
					if (res.data.code == 200) {
						self.dataSource = res.data.result.records
						self.pageCount = res.data.result.total
					} else {
						PopupCommon.notify("error", res.data.message)
					}
				})
			},
		},
		mounted() {
			this.initPage()
		},
	}
</script>

<style></style>
